﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-06-09 14:13:38
 * 功能：横幅广告
**************************************************************************************/

using UnityEngine;

public class Banner : AdBase
{
    public Banner(string adUnitId) : base(adUnitId)
    {
        m_AdType = EAdType.Banner;
    }

    public override void Initialize()
    {
        //var adViewConfiguration = new MaxSdk.AdViewConfiguration(MaxSdk.AdViewPosition.BottomCenter);
        MaxSdk.CreateBanner(m_AdUnitId, MaxSdkBase.BannerPosition.BottomCenter);
        MaxSdk.SetBannerBackgroundColor(m_AdUnitId, Color.black);

        MaxSdkCallbacks.Banner.OnAdLoadedEvent += OnLoadedEvent;
        MaxSdkCallbacks.Banner.OnAdLoadFailedEvent += OnLoadFailedEvent;
        MaxSdkCallbacks.Banner.OnAdClickedEvent += OnClickedEvent;
        MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
        MaxSdkCallbacks.Banner.OnAdExpandedEvent += OnDisplayedEvent;
        MaxSdkCallbacks.Banner.OnAdCollapsedEvent += OnHiddenEvent;

        LoadAd();
    }

    protected override void OnLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
    {
        base.OnLoadedEvent(adUnitId, adInfo);
    }

    public override void Show(ETriggerAdType type)
    {
        MaxSdk.ShowBanner(m_AdUnitId);
    }

    public void Hide()
    {
        MaxSdk.HideBanner(m_AdUnitId);
    }

    public void Destroy()
    {
        MaxSdk.DestroyBanner(m_AdUnitId);
    }

    public void StartAutoRefush()
    {
        MaxSdk.StartBannerAutoRefresh(m_AdUnitId);
    }

    public void StopAutoRefush()
    {
        MaxSdk.StopBannerAutoRefresh(m_AdUnitId);
    }

    /// <summary>手动刷新横幅广告</summary>
    public void Refush()
    {
        StopAutoRefush();
        MaxSdk.LoadBanner(m_AdUnitId);
    }
}